package com.share.service.impl;

import com.share.mapper.UserMapper;
import com.share.domain.User;
import com.share.service.IRoleService;
import com.share.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * caifan 2017/9/3
 */
@Service
public class UserService implements IUserService {
    @Autowired
    private UserMapper userMapper;
    @Autowired
    IRoleService roleService;

    @Override
    public User findById(Long id) {
        return userMapper.findById(id);
    }


    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    public void insertUser(User user) {
        try {
            roleService.insert(user.getRole());
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        if (user != null) {
            userMapper.insertUser(user);
        }
    }
   /* @Override
    public List<User> findAllUser() {
        return userMapper.findAllUser();
    }*/
}
